package others;

import beans.Slil;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.test.context.ContextConfiguration;
import services.impl.SlilServicesImpl;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Date;

@Component
@Aspect
@ContextConfiguration(locations = {"classpath:SpringMybatis.xml"})
public class ContactAop {
    @Autowired
    private SlilServicesImpl slilServices;
    @Pointcut("execution(* services.impl.ContactServicesImpl.updateByPrimaryKeySelective())")
    public void ContactUpdate(){}
    @Pointcut("execution(* services.impl.ContactServicesImpl.selectSelective())")
    public void ContactSelect(){}
    @Pointcut("execution(* services.impl.ContactServicesImpl.deleteByPrimaryKey())")
    public void ContactDelete(){}
    @Pointcut("execution(* services.impl.ContactServicesImpl.insertSelective())")
    public void ContactCreate(){}


    @After("ContactCreate()")
    public void Create() throws UnknownHostException {
        InetAddress addr = InetAddress.getLocalHost();
        Slil slil = new Slil();
        slil.setSlilMoname("联系人管理");
        slil.setSlilFunction("创建");
        slil.setSlilLoginip(addr.getHostAddress());
        slil.setSlilOptime(new Date());
        slilServices.insertSelective(slil);
        System.out.println("创建");
    }

    @After("ContactUpdate()")
    public void Select() throws UnknownHostException {
        InetAddress addr = InetAddress.getLocalHost();
        Slil slil = new Slil();
        slil.setSlilMoname("联系人管理");
        slil.setSlilFunction("修改");
        slil.setSlilLoginip(addr.getHostAddress());
        slil.setSlilOptime(new Date());
        slilServices.insertSelective(slil);
        System.out.println("修改");
    }

    @After("ContactDelete()")
    public void Delete() throws UnknownHostException {
        InetAddress addr = InetAddress.getLocalHost();
        Slil slil = new Slil();
        slil.setSlilMoname("联系人管理");
        slil.setSlilFunction("删除");
        slil.setSlilLoginip(addr.getHostAddress());
        slil.setSlilOptime(new Date());
        slilServices.insertSelective(slil);
        System.out.println("删除");
    }

    @After("ContactSelect()")
    public void Update() throws UnknownHostException {
        InetAddress addr = InetAddress.getLocalHost();
        Slil slil = new Slil();
        slil.setSlilMoname("联系人管理");
        slil.setSlilFunction("搜索");
        slil.setSlilLoginip(addr.getHostAddress());
        slil.setSlilOptime(new Date());
        slilServices.insertSelective(slil);
        System.out.println("搜索");
    }

}
